<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <div class="goto">
        <router-link to="/takesite">
          <img src="../../assets/home_img/left.png" alt="">
        </router-link>
      </div>
      <p>添加收货地址</p>
    </div>
    <div style="height: 2.4rem"></div>
    <!-- 内容 -->
    <div class="content">
      <div style="height: 3rem"></div>
      <div class="import">
        <p>收货人姓名：</p>
        <input type="text" class="input" placeholder="输入收货人姓名" v-model="contact">
        <span class="importtext">*必填</span>
      </div>
      <div class="import">
        <p>收货人电话：</p>
        <input type="number" class="input" placeholder="输入收货人电话" oninput="if(value.length>11)value=value.slice(0,11)" v-model="mobile">
        <span class="importtext">*必填</span>
      </div>
      <div class="import1">
        <p>收货人地址：</p>
        <textarea class="siteTextarea" placeholder="输入收货人地址，如：__省__市__区__路__小区__号楼__单元__室" v-model="address"></textarea>
        <span class="importtext">*必填</span>
      </div>

      <div class="ok" @click="okup()">
        <p>提 交</p>
      </div>

    </div>

    <div class="winshow" v-if="winshow">
      <div class="an"></div>
      <div class="ming">
        <div class="mingtext">
          <p>{{msgtext}}</p>
          <!--<p>{{msgnumber}}</p>-->
        </div>
        <div class="mingbtnbox">
          <div class="mingbtn" @click="winnone()">
            <p>确定</p>
          </div>
        </div>
      </div>
    </div>
    <div class="winshow" v-if="winshow1">
      <div class="an"></div>
      <div class="ming">
        <div class="mingtext">
          <p>{{msgtext}}</p>
          <!--<p>{{msgnumber}}</p>-->
        </div>
        <div class="mingbtnbox">
          <div class="mingbtn" @click="winnone1()">
            <p>确定</p>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    data(){
      return{
        address:'',
        contact:'',
        mobile:'',

        //   提示框
        winshow:false,
        winshow1: false, //成功
        msgtext:'',
      }
    },
    components:{

    },
    created(){

    },
    methods:{
      okup(){
        if (this.contact == ''){
          this.winshow = true;
          this.msgtext = '姓名不能为空';
        } else {
          if (this.mobile == ''){
            this.winshow = true;
            this.msgtext = '电话不能为空';
          } else {
            if(this.address == ''){
              this.winshow = true;
              this.msgtext = '地址不能为空';
            }else {
              let postData = this.$qs.stringify({
                storeId: 1,
                //  收货地址
                address:this.address,
                //  联系人
                contact:this.contact,
                //  手机号
                mobile:this.mobile,
                //   地址ID
                deliveryId: this.$route.query.id,
              });
              this.$axios({
                method:'POST',
                url:'api/address/edit',
                data:postData
              }).then((res)=>{
                console.log(res.data.msg);
                this.winshow1= true;
                this.msgtext = '添加成功！';
              }).catch((err)=>{
                console.log(err);
              })
            }
          }
        }
      },
      winnone(){
        this.winshow = false;
      },
      winnone1(){
        this.$router.replace({
          path:'/takesite',
        });
      }



    },

  }

</script>

<style scoped>
  *{
    margin: 0;
    padding: 0;
  }
  .header {
    width: 100%;
    height: 2.4rem;
    text-align: center;
    background: #609FE0;
    z-index: 999;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }
  .header p {
    line-height: 2.4rem;
    font-size: 1.05rem;
    color: white;
    font-weight: bolder;
  }
  .goto {
    position: relative;
  }
  .goto img {
    width: 1.8rem;
    height: 1.8rem;
    position: absolute;
    top: 0.3rem;
    left: 0.15rem;
  }
  /* 内容 */
  .content {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    background: white;
  }
  .import p {
    line-height: 4rem;
    margin-left: 0.6rem;
    font-size: 0.93rem;
    display: inline;
    color: #555555;
  }
  .import1 p {
    line-height: 2.5rem;
    margin-left: 0.6rem;
    font-size: 0.93rem;
    color: #555555;
  }
  .input {
    border: 1px solid gainsboro;
    outline: 0;
    width: 9rem;
    height: 1.6rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    color: #666666;
    padding-left: 0.3rem;
  }
  .importtext {
    color: #E63838;
    font-size: 0.8rem;
    margin-left: 0.4rem;
  }
  .siteTextarea {
    outline: 0;
    border: 1px solid gainsboro;
    border-radius: 0.25rem;
    padding-left: 0.6rem;
    padding-top: 0.3rem;
    width: 70%;
    margin-left: 10%;
    height: 4rem;
    font-size: 0.85rem;
    color: #666666;
  }
  .ok {
    margin-top: 13rem;
    width: 80%;
    margin-left: 10%;
    height: 2.3rem;
    text-align: center;
    background: #609FE0;
    border-radius: 0.25rem;
  }
  .ok p {
    line-height: 2.3rem;
    color: white;
    font-size: 0.95rem;
  }

  /*  提示框  */
  .winshow {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
  }
  .an {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    background: black;
    opacity: 0.4;
  }
  .ming {
    width: 80%;
    height: 10rem;
    background: white;
    position: fixed;
    top: 30%;
    left: 10%;
    border-radius: 0.25rem;
  }
  .mingtext {
    text-align: center;
    height: 6.8rem;
  }
  .mingtext p {
    line-height: 6.8rem;
    /*padding-top: 1rem;*/
    font-size: 0.85rem;
    color: #666666;
  }
  .mingbtnbox {
    text-align: center;
    border-top: 1px solid gainsboro;
  }
  .mingbtn {
    width: 5rem;
    border: 1px solid gainsboro;
    border-radius: 0.25rem;
    margin-top: 0.6rem;
    /*margin-left: 6.8rem;*/
    display: inline-block;
  }
  .mingbtn p {
    line-height: 1.9rem;
    color: #666666;
    font-size: 0.88rem;
  }

</style>